/*
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package gun0912.tedbottompicker.util;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;


public class ToastMaster {
    private static  Context mContext;
    private ToastMaster() {

    }

    public static void popToast(Context context, String toastText, int during) {
        if (context == null) {
            return;
        }
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing())
                return;
        }
        Toast sToast = Toast.makeText(context, toastText, during);
        Log.d("ToastHelper", "text=" + toastText);
        sToast.show();
    }

    public static void popToast(Context context, int textId, int during) {
        if (context == null) {
            return;
        }
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing())
                return;
        }
        Toast sToast = Toast.makeText(context, textId, during);
        Log.d("ToastHelper", "text=" + textId);
        sToast.show();
    }



    public static void toastAboveBottom(Context context, String text) {
        if (context == null) {
            return;
        }
        if (context instanceof Activity) {
            if (((Activity) context).isFinishing())
                return;
        }
        Toast sToast = Toast.makeText(context, text, Toast.LENGTH_SHORT);

        sToast.setGravity(Gravity.BOTTOM, sToast.getXOffset() / 2, (int) (ViewUtils.getDisplayHeight() / 1.8f));
//		sToast.setGravity(Gravity.BOTTOM,sToast.getXOffset()/2, (int) (sToast.getYOffset()/3.3f));
        sToast.show();
        Log.d("ToastHelper", "text=" + text);
    }

    public static void popToast(Context context, int textId) {
        popToast(context, textId, Toast.LENGTH_SHORT);
    }

    public static void popToast(Context context, String toastText) {
        popToast(context, toastText, Toast.LENGTH_SHORT);
    }

    public static void shortToast(String toastText) {
        popToast(mContext, toastText, Toast.LENGTH_SHORT);
    }


//    /**
//     * 默认是录音时间太短
//     *
//     * @param context
//     * @param imageResId
//     * @param tips
//     */
//    @SuppressLint("InflateParams")
//    public static void popCenterTips(Context context, int imageResId, String tips) {
//        if (context == null) {
//            return;
//        }
//        if (context instanceof Activity) {
//            if (((Activity) context).isFinishing())
//                return;
//        }
//        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        View layout = inflater.inflate(R.layout.toast_tips, null);
//        ImageView img = (ImageView) layout.findViewById(R.id.mall_tips1);
//        TextView text = (TextView) layout.findViewById(R.id.mall_tips2);
//        if (imageResId > 0)
//            img.setBackgroundResource(imageResId);
//        if (!TextUtils.isEmpty(tips))
//            text.setText(tips);
//        Toast toast = new Toast(context);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.setView(layout);
//        toast.show();
//    }
//
//
//    /**
//     * 默认是录音时间太短
//     *
//     * @param context
//     * @param imageResId
//     * @param tips
//     */
//    @SuppressLint("InflateParams")
//    public static void popCenterHTips(Context context, int imageResId, String tips) {
//        if (context == null) {
//            return;
//        }
//        if (context instanceof Activity) {
//            if (((Activity) context).isFinishing())
//                return;
//        }
//        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        View layout = inflater.inflate(R.layout.toast_h_tips, null);
//        ImageView img = (ImageView) layout.findViewById(R.id.mall_tips1);
//        TextView text = (TextView) layout.findViewById(R.id.mall_tips2);
//        if (imageResId > 0)
//            img.setBackgroundResource(imageResId);
//        if (!TextUtils.isEmpty(tips))
//            text.setText(tips);
//        Toast toast = new Toast(context);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.setView(layout);
//        toast.show();
//    }
//
//
//    @SuppressLint("InflateParams")
//    public static void popCenterTips(Context context, String tips) {
//        if (context == null) {
//            return;
//        }
//        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        View layout = inflater.inflate(R.layout.toast_center_tips, null);
//        TextView text = (TextView) layout.findViewById(R.id.mall_tips);
//        if (!TextUtils.isEmpty(tips))
//            text.setText(tips);
//        Toast toast = new Toast(context);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.setView(layout);
//        toast.show();
//    }
//
//    @SuppressLint("InflateParams")
//    public static void popCenterTips(Context context, String tips, String title) {
//        if (context == null) {
//            return;
//        }
//        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//        View layout = inflater.inflate(R.layout.toast_center_title_tips, null);
//        TextView text = (TextView) layout.findViewById(R.id.mall_tips);
//        TextView textTitle = (TextView) layout.findViewById(R.id.mall_tips_title);
//        if (!TextUtils.isEmpty(tips))
//            text.setText(tips);
//        if (!TextUtils.isEmpty(title)) {
//            textTitle.setText(title);
//        }
//        Toast toast = new Toast(context);
//        toast.setGravity(Gravity.CENTER, 0, 0);
//        toast.setDuration(Toast.LENGTH_SHORT);
//        toast.setView(layout);
//        toast.show();
//    }

}
